import { http } from "@/utils/http";

// 广告接口类型定义
export interface Advert {
  id: string; // 广告位编号
  name: string; // 广告名称
  status: number; // 广告状态
  cell: string; // 小区
  position: string; // 广告位置
  size: string; // 广告位大小
  price: number; // 广告价格
  image?: string; // 广告图片
  [key: string]: any;
}

export interface AdvertQueryParams {
  page?: number;
  size?: number;
  name?: string;
  id?: string;
  status?: number;
  cellId?: number;
  [key: string]: any;
}

// 广告列表响应
interface AdvertListData {
  advertList: Advert[];
  count: number;
}

export interface AdvertListResponse {
  code: number;
  data: AdvertListData; // 修改为正确的数据结构
  message: string;
}

// 通用响应接口
export interface ApiResponse<T = any> {
  code: number;
  data?: T;
  message: string;
}

// 上传广告
export const uploadAdvert = (formData: FormData) => {
  return http.request<ApiResponse>("post", "/advert/upload", {
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};

// 更新广告
export const updateAdvert = (data?: Advert) => {
  return http.request<ApiResponse>("post", "/advert/updateAdvert", { data });
};

// 添加广告
export const addAdvert = (data?: Advert) => {
  return http.request<ApiResponse>("post", "/advert/inertAdvert", { data });
};

// 根据条件分页查询
export const getAdvertList = (params?: AdvertQueryParams) => {
  return http.request<AdvertListResponse>(
    "post",
    "/advert/findAdvertByQueryDto",
    {
      data: params
    }
  );
};

// 根据id查询广告
export const getAdvertById = (id: string) => {
  return http.request<ApiResponse<Advert>>(
    "get",
    `/advert/findAdvertById?id=${id}`
  );
};

// 根据id删除广告
export const deleteAdvert = (id: string) => {
  return http.request<ApiResponse>("get", `/advert/deleteById?id=${id}`);
};
